package com.bytedance.danmaku.render.engine.demo.demo

import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.WindowManager
import android.widget.Button
import android.widget.EditText
import android.widget.ImageButton
import androidx.appcompat.app.AppCompatActivity
import com.bytedance.danmaku.render.engine.demo.R
import com.google.android.material.bottomsheet.BottomSheetDialog

class InputDemoActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_input_demo)
        findViewById<Button>(R.id.input_btn).setOnClickListener {
            showBottomSheetDialog()
        }
    }
    private fun showBottomSheetDialog() {
        val dialog = BottomSheetDialog(this)
        val view = LayoutInflater.from(this).inflate(R.layout.bottom_select_color, null)

        // 初始化视图
        val textInput = view.findViewById<EditText>(R.id.edit_text)
        val btnConfirm = view.findViewById<Button>(R.id.btn_confirm)

        // 颜色按钮
        val colorRed = view.findViewById<Button>(R.id.color_red)
        val colorGreen = view.findViewById<Button>(R.id.color_green)
        val colorBlue = view.findViewById<Button>(R.id.color_blue)
        val colorBlack = view.findViewById<Button>(R.id.color_black)

        // 设置颜色按钮点击事件
        colorRed.setOnClickListener { textInput.setTextColor(Color.RED) }
        colorGreen.setOnClickListener { textInput.setTextColor(Color.GREEN) }
        colorBlue.setOnClickListener { textInput.setTextColor(Color.BLUE) }
        colorBlack.setOnClickListener { textInput.setTextColor(Color.BLACK) }
//        colorPurple.setOnClickListener { textInput.setTextColor(Color.parseColor("#800080")) }

        // 自定义颜色选择器
//        colorCustom.setOnClickListener {
////            showColorPicker(textInput)
//        }

        // 确定按钮点击事件
        btnConfirm.setOnClickListener {
            val inputText = textInput.text.toString()
            if (inputText.isNotEmpty()) {
//                resultTextView.text = inputText
//                resultTextView.setTextColor(textInput.currentTextColor)
            }
            dialog.dismiss()
        }
        dialog.window?.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND)
        dialog.setContentView(view)
        dialog.show()
    }
}